<?php
class functions {

	private $token;
	
    function __construct() {
	
    }
	
	
	public function getTopStats(){
		$username = 'eric.angeloni@gmail.com';
		$password = '911911';

		// set up our request to get the token
		$restUrl = 'https://api.lotame.com/';

		//Post Arguements
		$postargs = 'email='.urlencode($username).'&password='.urlencode($password);

		//Get Auth Token
		$session = curl_init($restUrl);
		curl_setopt($session, CURLOPT_POST, true);
		curl_setopt($session, CURLOPT_POSTFIELDS, $postargs);
		curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
		$token = curl_exec($session);
		curl_close($session);
		$restUrl = "https://api.lotame.com/audstats/reports/topAudiences";

		$session = curl_init($restUrl);
		curl_setopt($session,CURLOPT_HTTPHEADER,array("Authorization: $token","Accept: application/json"));
		curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
		$jsonResponse = curl_exec($session);


		/* 
		  Lets's decode our string and then loop through, getting our
		  audiences.  We are treating everything as an array.
		  If we had wanted to work with objects instead we would use
			$jsonAudienceList = json_decode($jsonResponse);
		  instead and then loop through objects instead of arrays.
		*/
		//decode JSON
		$jsonAudienceList = json_decode($jsonResponse, true);
		return $jsonAudienceList;
	}
}
?>